package domain;

import android.app.Activity;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.util.Log;


public class GenericFunctions extends Activity
{
	String strLevelbat=null;
	String strGFunct="GenericFunctions";
	
	public GenericFunctions()
	{
		
	}
	////////////////////////////////////////////////BATTERY ////////////////////////////////////////
	public String strbatteryLevel()
	{
	
		BroadcastReceiver batteryLevelReceiver = new BroadcastReceiver()
		{
		
			public void onReceive(Context context, Intent intent) 
			{			
				context.unregisterReceiver(this);
				
				int rawlevel = intent.getIntExtra("level", -1);
				
				int scale = intent.getIntExtra("scale", -1);
				
				int levelbat = -1;
				
				if (rawlevel >= 0 && scale > 0) {
				
				levelbat = (rawlevel * 100) / scale;
				
				}
				//Log.i(TAG, "[strbatteryLevel] BATTERY int: " + levelbat);
				 strLevelbat = String.valueOf(levelbat);
				Log.i(strGFunct, "[strbatteryLevel] BATTERY str: " + strLevelbat);	
			}		
		};
		
		IntentFilter batteryLevelFilter = new IntentFilter(Intent.ACTION_BATTERY_CHANGED);    	
		this.registerReceiver(batteryLevelReceiver, batteryLevelFilter);
		Log.i(strGFunct, "[strbatteryLevel] BATTERY str final: " + strLevelbat);	
		
		return strLevelbat;
	}

	
	    
}
